import { STORE_PREFIX } from "@/utils/constant";
import { defineStore, storeToRefs } from "pinia";
import { useUserStore } from "./user";

export const usePremsStore = defineStore(
  `${STORE_PREFIX}_prems_store`,
  () => {
    const userStore = useUserStore();
    const { userInfo } = storeToRefs(userStore);
    const isRoomAdmin = computed(() => userInfo.value?.UserType == 2);
    const menus = computed(() => userInfo.value?.Perms.filter(item => item.MType == 0) || []);
    const applys = computed(() => userInfo.value?.Perms.filter(item => item.MType == 1) || []);
    const edits = computed(() => userInfo.value?.Perms.filter(item => item.MType == 2) || []);

    const isMenuSetting = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 1)
    );
    const isMenuUser = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 3)
    );
    const isMenuApply = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 4)
    );
    const isMenuReport = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 5)
    );
    const isMenuBackwater = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 25)
    );
    const isMenuActivity = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 6)
    );
    const isMenuMonitor = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 7)
    );
    const isMenuOdds = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 8)
    );
    const isMenuFlyalone = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 9)
    );
    const isMenuOpen = computed(
      () => isRoomAdmin.value || !!menus.value.find(item => item.Id == 10)
    );

    const isEditBasisSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 13)
    );
    const isEditGameSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 14)
    );
    const isEditUserSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 15)
    );
    const isEditAgentSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 16)
    );
    const isEditActivitySetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 17)
    );
    const isEditBackwaterSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 18)
    );
    const isEditMessageSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 20)
    );
    const isEditOddsSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 21)
    );
    const isEditTlementSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 22)
    );
    const isEditChatSetting = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 23)
    );
    const isEditDeleteReport = computed(
      () => isRoomAdmin.value || !!edits.value.find(item => item.Id == 24)
    );

    const isApplyUpdown = computed(
      () => isRoomAdmin.value || !!applys.value.find(item => item.Id == 11)
    );
    const isApplyJoinroom = computed(
      () => isRoomAdmin.value || !!applys.value.find(item => item.Id == 12)
    );
    return {
      isRoomAdmin,

      isMenuSetting,
      isMenuUser,
      isMenuApply,
      isMenuReport,
      isMenuBackwater,
      isMenuActivity,
      isMenuMonitor,
      isMenuOdds,
      isMenuFlyalone,
      isMenuOpen,

      isEditBasisSetting,
      isEditGameSetting,
      isEditUserSetting,
      isEditAgentSetting,
      isEditActivitySetting,
      isEditBackwaterSetting,
      isEditMessageSetting,
      isEditOddsSetting,
      isEditTlementSetting,
      isEditChatSetting,
      isEditDeleteReport,

      isApplyUpdown,
      isApplyJoinroom
    };
  },
  {
    persist: {
      storage: sessionStorage
    }
  }
);
